<template>
  <div class="singer">
    <index-list :data="singers" @select="selectSinger"/>
    <router-view #default="{Component}" >
      <transition name="slide">
        <Component :is="Component" :data="selectedSinger"></Component>
      </transition>
    </router-view>
  </div>
</template>

<script>
import { getSingerList } from '@/service/singer'
import IndexList from '@/components/base/index-list/index-list.vue'
import { SINGER_KEY } from '@/assets/js/constant'

export default {
  components: { IndexList },
  data () {
    return {
      singers: [],
      selectedSinger: null
    }
  },
  async created () {
    const result = await getSingerList()
    this.singers = result.singers
  },
  methods: {
    selectSinger (singer) {
      this.selectedSinger = singer
      this.cacheSinger(singer)
      this.$router.push(`/singer/${singer.mid}`)
    },
    cacheSinger (singer) {
      sessionStorage.setItem(SINGER_KEY, JSON.stringify(singer))
    }
  }
}
</script>

<style lang="scss" scoped>
// ！！！必须，否则鼠标点击时无法滚动
// 否则无法触发滚动事件
.singer{
  position: fixed;
  width: 100%;
  top: 88px;
  bottom: 0;
}
</style>
